package springboot.demo.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springboot.demo.annotation.NotProfile;
import springboot.demo.bean.Novel;
import springboot.demo.dto.ResultDTO;
import springboot.demo.service.NovelService;

@RestController
@Slf4j
@NotProfile("simple")
public class NovelController {

    @Autowired
    NovelService novelService;

    @RequestMapping("/v1/getNovel")
    public ResultDTO<Novel> getNovelName(int id) {
        Novel novel = novelService.getNovelById(id);
        log.info("novel:{}", JSON.toJSONString(novel));
        return ResultDTO.success(novel);
    }

    @PostMapping("/v1/pageQuery")
    public ResultDTO<Page<Novel>> pageQueryNovel(@RequestBody Page<Novel> pageReq) {
        return ResultDTO.success(novelService.pageQuery(pageReq));
    }

}
